package com.ls.demo.controller;

import com.github.pagehelper.PageInfo;
import com.ls.demo.common.Result;
import com.ls.demo.entity.Metrics;
import com.ls.demo.entity.Notice;
import com.ls.demo.service.MetricsService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/metrics")
public class MetricsController {
    @Resource
    private MetricsService metricsService;
    /**
     * 新增
     */
    @PostMapping("/add")
    public Result add(@RequestBody Metrics metrics) {
        metricsService.add(metrics);
        return Result.success();
    }

    /**
     * 修改
     */
    @PutMapping("/update")
    public Result update(@RequestBody Metrics metrics ) {
        metricsService.updateById(metrics);
        return Result.success();
    }

    /**
     * 单个删除
     */
    @DeleteMapping("/delete/{id}")
    public Result delete(@PathVariable Integer id) {
        metricsService.deleteById(id);
        return Result.success();
    }

    /**
     * 批量删除
     */
    @DeleteMapping("/delete/batch")
    public Result delete(@RequestBody List<Integer> ids) {
        metricsService.deleteBatch(ids);
        return Result.success();
    }

    /**
     * 单个查询
     */
    @GetMapping("/selectById/{id}")
    public Result selectById(@PathVariable Integer id) {
        Metrics metrics = metricsService.selectById(id);
        return Result.success(metrics);
    }

    /**
     * 查询所有
     */
    @GetMapping("/selectAll")
    public Result selectAll(Metrics metrics) {
        List<Metrics> list = metricsService.selectAll(metrics);
        return Result.success(list);
    }

    /**
     * 分页查询
     */
    @GetMapping("/selectPage")
    public Result selectPage(Metrics metrics,
                             @RequestParam(defaultValue = "1") Integer pageNum,
                             @RequestParam(defaultValue = "10") Integer pageSize) {
        PageInfo<Metrics> pageInfo = metricsService.selectPage(metrics, pageNum, pageSize);
        return Result.success(pageInfo);
    }
}
